import 'package:base_lib/common/index.dart';
import 'package:base_lib/config.dart';
import 'package:base_lib/index.dart';
import 'package:doctor_login_lib/cache/userinfo_cache.dart';
import 'package:doctor_prescribe_lib/doctor_prescribe_component.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

///处方工具
class PrescribeUtil {
  static String formatMoney(double num) {
   return Config.formatMoney(num);
  }

  /// 格式化金额(格式化总价时展示用)
  static String formatMoneyForSumShow(num money) {
    return Config.formatMoneyForSumShow(money);
  }


  ///展示开处方弹窗
  static void showPrescribeDialog(BuildContext context) async {
    var doctorUser = await UserInfoCache.getInstance().get();
    if (doctorUser == null) {
      Routers.navigateTo(context, Routers.login_page);
      return;
    }

    var height = 200.0;
    var oneItemHeight = height / 3 - 5;
    CustomDialog.customDialog(context,
        child: Container(
          width: ScreenAdapter.screenWidthDp * 0.82,
          height: height,
          decoration: BoxDecoration(
              color: Colors.white, borderRadius: BorderRadius.circular(20)),
          child: Column(
            children: [
              Expanded(
                child: Row(
                  children: [
                    Spacer(),
                    Text(
                      '选择处方类型',
                      style: TextStyle(
                          fontSize: 16,
                          fontWeight: FontWeight.bold,
                          color: Colors.black),
                    ),
                    Expanded(
                      child: IconButton(
                        onPressed: () {
                          Navigator.pop(context);
                        },
                        icon: Icon(Icons.close),
                      ),
                    )
                  ],
                ),
              ),
              1.gapVdp(Colors.grey[200]),
              Expanded(
                child: FlatButton(
                  onPressed: () {
                    Navigator.pop(context);
                    Routers.navigateTo(
                      context,
                      DoctorPrescribeComponent.offlineBasicInfoPage,
                      parameters: Parameters()
                        ..putString('title', '基本信息(西药)')
                        ..putInt('rxType', 0)
                        ..putInt('medicineFormID', 0)
                        ..putInt('inquiryID', 0)
                        ..putObj('talkInfo', {}),
                    );
                  },
                  child: Text(
                    '西药',
                    style: TextStyle(
                        color: ThemeGlobal
                            .instance.themeData.themeColor.themeColor),
                  ),
                ),
              ),
              1.gapVdp(Colors.grey[200]),
              Expanded(
                child: Row(
                  children: [
                    Expanded(
                      child: FlatButton(
                        onPressed: () {
                          Navigator.pop(context);
                          Routers.navigateTo(
                            context,
                            DoctorPrescribeComponent.offlineBasicInfoPage,
                            parameters: Parameters()
                              ..putString('title', '基本信息(中饮)')
                              ..putInt('rxType', 1)
                              ..putInt('medicineFormID', 10)
                              ..putInt('inquiryID', 0)
                              ..putObj('talkInfo', {}),
                          );
                        },
                        child: Text(
                          '中药饮片',
                          style: TextStyle(
                              color: ThemeGlobal
                                  .instance.themeData.themeColor.themeColor),
                        ),
                      ),
                    ),
                    Container(
                      width: 1,
                      height: oneItemHeight,
                      color: Colors.grey[200],
                    ),
                    Expanded(
                      child: FlatButton(
                        onPressed: () {
                          Navigator.pop(context);
                          Routers.navigateTo(
                            context,
                            DoctorPrescribeComponent.offlineBasicInfoPage,
                            parameters: Parameters()
                              ..putString('title', '基本信息(中剂)')
                              ..putInt('rxType', 1)
                              ..putInt('medicineFormID', 11)
                              ..putInt('inquiryID', 0)
                              ..putObj('talkInfo', {}),
                          );
                        },
                        child: Text(
                          '中药颗粒剂',
                          style: TextStyle(
                              color: ThemeGlobal
                                  .instance.themeData.themeColor.themeColor),
                        ),
                      ),
                    )
                  ],
                ),
              ),
            ],
          ),
        ));
  }
}
